module ApplicationHelper


  def today_count
    td = Date.today
    tm = td+1
    tmt = tm.to_time
    tmt = tmt-1
    CreditRecord.where(created_at: td.to_time..tmt).count
  end


  def nav_active(hsh = {})
    _same_controller = hsh[:controller] == self.controller_name
    _same_action = hsh[:action] == self.action_name
    unless hsh[:action]
      return _same_controller ? 'active' : ''
    end
    unless hsh[:controller]
      return _same_action ? 'active' : ''
    end
    (_same_controller && _same_action) ? 'active' : ''
  end

  #
  def ufile_public(image_name)
    "http://#{bucket_name}.oss-cn-beijing.aliyuncs.com/"+ image_name
  end

  #
  def ufile_public_src(image_name)
    "http://#{bucket_name}.oss-cn-beijing.aliyuncs.com/"+ image_name
  end
  #
  def ufile_public_src_static(image_name)
    "http://#{bucket_name}.oss-cn-beijing.aliyuncs.com/static/"+ image_name
  end

  private
  def bucket_name
     Rails.env.development? ? 'graylist' : 'xjgl'
  end
end
